#ifndef _PID_H_
#define _PID_H_

#include "headfile.h"

enum
{
    POSITION_PID = 0, // 位置式
    DELTA_PID,        // 增量式
};

enum STATUS
{
    ANGLE_SPEED = 0, //角度换串速度环
    POSITION_SPEED,  //位置环串速度环
	TRACK_SPEED,     //速度环循迹
    STOP,
};

typedef struct
{
    float target;
    float now;
    float error[3];
    float p, i, d;
    float pout, dout, iout;
    float out;

    uint32_t pid_mode;

} pid_t;

extern pid_t motorA;
extern pid_t motorB;
extern pid_t angle;
extern pid_t positionA;
extern pid_t positionB;
extern float TempA, TempB;
extern int SpeedA_reference; // 基准速度
extern int SpeedB_reference; // 基准速度
extern int Expand;
extern float target_angle; //目标角度，在白线时依靠此值走直线
extern float angle_diff;


//PID-related functions
void pid_init(pid_t *pid, uint32_t mode, float p, float i, float d);
void pid_cal(pid_t *pid);
void pidout_limit(pid_t *pid);
//Speed loop-related functions
void speed_target(int spe1, int spe2);
int speed_now(int dir);
void speed_out(void);
//position loop-realted functions
void position_now(void);
void position_out();
void position_target(float circle);
void position_default(void);
int mapValue(int maxValue, int value);
//angle loop-related functions
void angle_now(void);
void angle_out(void);
void angle_target(float target);
float angle_turn(float angle);
//overall PID-control
void pid_setValue(void);
void PID_Overall_Contral(uint8_t status);


#endif